<template>
  <div>
    <h1>多个元素应用同一个过渡</h1>
    <button @click="isShow = !isShow">显示/隐藏</button>
    <!-- 
        name: 自定义过渡动画类名称前缀，默认值 v
        appear: 首次渲染时是否应用过渡动画
     -->
    <transition-group>
      <h1 v-show="isShow" key="1">Test</h1>
      <h1 v-show="isShow" key="2">Test</h1>
    </transition-group>

    <transition-group name="test">
      <h1 v-show="!isShow" key="1">Test1</h1>
      <h1 v-show="isShow" key="2">Test2</h1>
    </transition-group>
  </div>
</template>

<script>
export default {
  name: "Test",
  data() {
    return {
      isShow: true,
    };
  },
  methods: {},
};
</script>

<style scoped>
h1 {
  background-color: salmon;
  color: #fff;
  padding: 20px 50px;
  width: 300px;
}

.v-enter-active {
  animation: myAnimation 1s ease-in-out;
}

.v-leave-active {
  animation: myAnimation 1s ease-in-out reverse;
}

.test-enter-active {
  animation: myAnimation 1s ease-in-out;
}

.test-leave-active {
  animation: myAnimation 1s ease-in-out reverse;
}
@keyframes myAnimation {
  from {
    transform: translateX(-100%);
  }
  to {
    transform: translateX(0px);
  }
}
</style>
